package com.zhonghui.procurement.controller;

import com.zhonghui.procurement.domain.ProcurementPushUser;
import com.zhonghui.procurement.domain.vo.ProcurementPushUserListVo;
import com.zhonghui.procurement.domain.vo.ProcurementPushUserVo;
import com.zhonghui.procurement.service.IProcurementPushUserService;
import com.zhonghui.response.BaseResult;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import static com.zhonghui.common.utils.PageUtils.startPage;

@RestController
@RequestMapping("/procurement/UserPush")
public class ProcurementPushUserController {

    @Autowired
    private IProcurementPushUserService procurementPushUserService;

    /**
     * 查询采购-用户推送列表
     */
    @GetMapping("/list")
    public BaseResult list(ProcurementPushUser procurementPushUser)
    {
//        startPage();
        ProcurementPushUserListVo procurementPushUserListVo = new ProcurementPushUserListVo();
        List<ProcurementPushUserVo> list = procurementPushUserService.selectProcurementPushUserList(procurementPushUser);
        procurementPushUserListVo.setProcurementPushUserVoList(list);
//        遍历计算未读数量
        for (ProcurementPushUserVo procurementPushUserVo : list) {
            if (procurementPushUserVo.getPushStatus() == null){
                procurementPushUserVo.setPushStatus("0");
                procurementPushUserListVo.setNumber(procurementPushUserListVo.getNumber()+1);
            }
        }
        return BaseResult.success(procurementPushUserListVo);
    }

    @PutMapping("/updateStatus")
    public BaseResult updateStatus(Integer listId){
        String msg = procurementPushUserService.updateStatus(listId);
        return BaseResult.success(msg);
    }

}
